<template>
  <div class="personal-center">
    <Header title="个人中心">
      <!--      <van-tag class="text-tag" type="danger" size="large">温馨提示：【未提供最终内容】</van-tag>-->
    </Header>
    <div>
      <div class="user-info">
        <img src="~@/assets/img/avater-img.png" class="avater"/>
        <p class="user-name">{{ fakexm }}</p>
      </div>
      <template v-for="(item, index) in menuList">
        <van-cell :key="index" :to="item.to" :url="item.url" v-show="item.show" is-link>
          <template #title>
            <div class="flex-align-center">
              <img :src="item.icon" class="item-icon"/>
              <p>{{ item.name }}</p>
            </div>

          </template>
        </van-cell>
      </template>

      <div class="handler-btn">
        <van-button size="normal" round type="info" @click="goPage('Home')" class="btn">返回首页</van-button>
        <van-button size="normal" round type="danger" native-type="button" @click="signOut" class="btn">退出系统
        </van-button>
      </div>
    </div>
    <van-dialog v-model="noPassShow" class="no-pass-style" show-cancel-button @confirm="goPage('UserInfo')">
      <p class="shzt">您的参会信息审核<span class="shyy">不通过</span></p>
      <p class="shyy">审核不通过的原因：{{ selfUserInfo.shyy }}</p>
      <p>是否前去”参会报名“进行修改并提交</p>
    </van-dialog>
  </div>
</template>

<script>
import { loadUserInfo, checkDoctorPermission } from 'api/userInfo'
import { getAccessToken, setSelfInfo, logout } from '@/utils/tokenUtil'

export default {
  name: 'PersonalCenter',
  data() {
    return {
      fakexm: '***',
      menuList: [
        {
          name: '参会报名',
          to: 'userInfo',
          show: true,
          icon: require('../../../src/assets/img/icon/info-icon.png')
        },
        {
          name: '健康信息上传',
          to: 'uploadHealth',
          show: true,
          icon: require('../../../src/assets/img/icon/health-icon.png')
        },
        {
          name: '每日健康申报',
          to: 'illnessReport',
          show: true,
          icon: require('../../../src/assets/img/icon/illnessReport-icon.png')
        },
        {
          name: '人员管理',
          to: 'personManager',
          show: false,
          icon: require('../../../src/assets/img/icon/manager-icon.png')
        },
        {
          name: '参会报名审核',
          to: 'illnessReportManager',
          show: false,
          icon: require('../../../src/assets/img/icon/examie-icon.png')
        },
        {
          name: '添加参会人员',
          to: 'addUser',
          show: false,
          icon: require('../../../src/assets/img/icon/addUser-icon.png')
        },
        {
          name: '消息公告',
          to: 'notifyManager',
          show: true,
          icon: require('../../../src/assets/img/icon/notify-icon.png')
        },
        {
          name: '饭票扫码',
          to: 'lunchManager',
          show: false,
          icon: require('../../../src/assets/img/icon/notify-icon.png')
        },
        {
          name: '酒店及用餐信息查阅',
          to: 'hotelInfo',
          show: true,
          icon: require('../../../src/assets/img/icon/hotel-icon.png')
        },
        {
          name: '每日午餐申报',
          to: 'orderFood',
          show: false,
          icon: require('../../../src/assets/img/icon/food-icon.png')
        },
        {
          name: '开/闭幕式手册',
          to: 'kbmsPage',
          show: true,
          icon: require('../../../src/assets/img/icon/kbms-icon.png')
        },
        {
          name: '防疫手册',
          to: {
            name: 'FyzyDetail',
            params: {
              title: '防疫手册',
              pdfName: './pdf/fysc.pdf'
            }
          },
          show: true,
          icon: require('../../../src/assets/img/icon/kbms-icon.png')
        }
        // {
        //   name: '常见问题答疑',
        //   url: 'https://docs.qq.com/sheet/DY3ppUkVlekNUZkhK?tab=BB08J2',
        //   show: true,
        //   icon: require('../../../src/assets/img/icon/question-icon.png')
        // }
      ],
      zjSrc: '',
      selfUserInfo: {},
      noPassShow: false
    }
  },
  mounted() {
    this.loadPersonCenterInfo()
  },
  methods: {
    goPage(name) {
      this.$router.push({ name })
    },
    loadPersonCenterInfo() {
      // console.log('根据token(手机号码)加载本业需要的信息，包括是否“姓名”、“个人信息保存标记”等')
      loadUserInfo({ tel: getAccessToken() })
        .then(res => {
          let rs = JSON.parse(res.data)
          rs = rs[0]
          // 如果参会信息审核不通过，弹窗提醒
          this.noPassShow = rs.shzt == '2' ? true : false
          setSelfInfo(rs)
          this.selfUserInfo = rs
          if (!!!rs.zae036 && (rs.chlx != '5' && rs.chlx != '8')) {
            // 领队和联络管理员不需要保存也可以
            console.log('还没有保存过个人信息，重定向到个人信息页面')
            this.$router.push({ name: 'UserInfo' })
          } else {
            this.fakexm = rs.fakexm
            // this.$set(this.menuList[2], 'show', rs.ismanager)
            let isManager = false
            if ('true' == rs.ismanager) {
              isManager = true
            }
            this.$set(this.menuList[3], 'show', isManager)
            this.$set(this.menuList[4], 'show', isManager)
            this.$set(this.menuList[5], 'show', isManager)
            // 赛馆工作人员，开闭幕式工作人员，执行机构工作人员不需要显示每日订餐
            let orderArr = [19, 20, 21, 22]
            if (orderArr.indexOf(parseInt(rs.chlx)) > -1) {
              this.$set(this.menuList[9], 'show', false)
            } else {
              this.$set(this.menuList[9], 'show', true)
            }
            // 非参赛代表团人员再去查看赛务通权限

            if (parseInt(rs.tdbh) > 47) {
              checkDoctorPermission({ idcard: rs.idcard }).then((res) => {
                if (res.data != '{}') {
                  let permission = JSON.parse(res.data).permission
                  let view = permission.BSTVIEWPERMIS
                  if (view == 'true') {
                    this.$set(this.menuList[3], 'show', true)
                    this.$set(this.menuList[4], 'show', true)
                  }
                  rs.permission = permission
                  setSelfInfo(rs)
                }
              })
            }
          }
        })
    },
    signOut() {
      logout()
      this.$router.push({ name: 'Login' })
    }

  }
}
</script>

<style lang="scss" scoped>
.user-info {
  display: flex;
  align-items: center;
  font-size: 0.6rem;
  background-color: white;
  margin-bottom: 10px;
  padding: 15px;

  .avater {
    //width: 1.5rem;
    //height: 1.5rem;
    ////border-radius: 50%;
    //border: 1px solid #ebedf0;
    width: 80px;
    margin-right: 15px;
  }

}

.item-icon {
  width: 28px;
  height: 28px;
  margin-right: 5px;
}

.handler-btn {
  margin: 20px 0;
  padding: 0 20px;
  display: flex;
  margin-left: -20px;

  .btn {
    flex: 1;
    margin-left: 20px;
  }

}

.no-pass-style {
  padding: 20px 10px 0;
  font-size: 14px;
  line-height: 1.8;

  .shyy {
    word-break: break-all;
    color: red;
  }
}
</style>
